<!--
 * @Author: mhb
 * @Date: 2021-12-21 17:38:02
 * @LastEditTime: 2022-01-11 17:13:31
 * @LastEditors: Please set LastEditors
 * @Description: 查看评审
 * @FilePath: \cscec-pms-admin-3\src\views\quality\resultsManagement\QCActivityResult\ViewData.vue
-->
<template>
  <div>
    <!-- 活动成果 -->
    <div class="mb20">
      <title-name title="活动成果"></title-name>
      <a-row type="flex" class="mb12">
        <excel ref="exportAll" fileName="活动成果" is-click-generate="false">
          <a-button
            :disabled="!form.achievements || !form.achievements.length"
            slot="excelBtn"
            icon="download"
            @click="exportAll"
            >全部导出</a-button
          >
        </excel>
        <a-button
          :loading="downLoading"
          icon="cloud-download"
          :disabled="!form.achievements || !form.achievements.length"
          @click="downZip(form.achievements, 'files')"
        >
          附件下载
        </a-button>
      </a-row>
      <a-table ref="table" rowKey="id" :dataSource="form.achievements || []" :pagination="false" :columns="columns">
        <!-- 操作：移除 -->
        <a
          slot="actions"
          slot-scope="text, record"
          @click="
            chooseRow = record
            $refs.viewResultData.visible = true
          "
          >查看</a
        >
      </a-table>
    </div>
    <!-- 评审成员 -->
    <div>
      <title-name title="评审成员"></title-name>
      <a-table rowKey="userId" :dataSource="form.employees || []" :columns="columns2" :pagination="false"></a-table>
    </div>
    <!-- 成果评审详情信息弹窗 -->
    <ViewResultData ref="viewResultData" :form="chooseRow" />
  </div>
</template>

<script>
import BasePage from '@/views/basePage'
import ViewResultData from '../components/ViewResultData' // 表单弹窗

export default {
  name: 'ViewData',
  extends: new BasePage(),
  components: {
    ViewResultData
  },
  props: {
    // 表单
    form: {
      type: Object,
      default: () => {}
    },
    // 请求api
    api: {
      type: Object,
      default: () => null
    }
  },
  data() {
    return {
      chooseRow: {}, //选中活动成果
      columns: [
        {
          dataIndex: 'projectName',
          title: '项目名称'
        },
        {
          dataIndex: 'topicName',
          title: '课题名称'
        },
        {
          dataIndex: 'topicTypeName',
          title: '课题类型'
        },
        {
          dataIndex: 'topicRegisterNumber',
          title: '课题注册号'
        },
        {
          dataIndex: 'completeEmployeeNames',
          title: '课题实际完成人'
        },
        {
          dataIndex: 'average',
          title: '资料平均分'
        },
        {
          dataIndex: 'deductPoints',
          title: '资料逾期扣分'
        },
        {
          dataIndex: 'score',
          title: '资料得分',
          customRender(e){
            return e > 0 ? e : 0
          }
        },
        {
          dataIndex: 'sort',
          title: '排名'
        },
        {
          dataIndex: 'status',
          title: '状态'
        },
        {
          dataIndex: 'actions',
          title: '操作',
          width: 80,
          scopedSlots: { customRender: 'actions' }
        }
      ], // 成果表头
      columns2: [
        {
          title: '姓名',
          ellipsis: true,
          dataIndex: 'name'
        },
        {
          title: '职称',
          ellipsis: true,
          dataIndex: 'jobTitle',
          customRender(e) {
            return e || '无'
          }
        },
        {
          title: '岗位',
          ellipsis:true,
          dataIndex: 'postPNames',
          customRender(e) {
            return e || '无'
          }
        },
        {
          title: '学历',
          ellipsis: true,
          dataIndex: 'specialitieMax',
          customRender(e) {
            return e || '无'
          }
        }
      ] // 人员表头
    }
  },
  mounted() {
    // 导出初始化
    this.$refs.exportAll.tableToExcelFile(this.$refs.table, 0)
  },
  methods: {
    /**
     * 导出全部
     */
    exportAll() {
      this.$refs.exportAll.setDataAndGenerate(this.form.achievements)
    },
    /**
     * 添加人员
     * @param {Array}} e -选中人员
     */
    handleAdd(e) {
      let employees = e.map((i) => ({
        userId: i.userId,
        name: i.name,
        jobTitle: i.jobTitle,
        postPNames: i.postPNames?.join('，'),
        specialitieMax: i.specialitieMax
      }))
      this.$set(this.form, 'employees', employees)
    }
  }
}
</script>
